﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VDataAdapter;
using VDataAdapter.PriceServerAdapter;

namespace TestVdataAdapter.PriceServerAdapter
{
    /// <summary>
    /// This class is to verify whether EventSimulator runs properly
    /// Can also be used to test events of price server
    /// </summary>
    class FooPriceServerEventHandler : IPriceServerEventHandler
    {
        private List<string> _data = new List<string>();

        public List<string> Data
        {
            get { return _data; }
        }

        private void AddItems(string[] items, string tag, List<string> data)
        {
            data.Add("<" + tag + ">");
            foreach (string item in items)
            {
                data.Add("<Item>" + item + "</Item>");
            }
            data.Add("</" + tag + ">");
        }

        public void GetFirstTime(IDictionary<string, PriceLibrary.PriceService.StockBase> basePrices, IDictionary<string, PriceLibrary.PriceService.StockBase> top3Prices)
        {
            _data.Add("<GetFirstTime>");
           
            AddItems(basePrices.Keys.ToArray(), "BasePrices", _data);

            AddItems(top3Prices.Keys.ToArray(), "Top3Prices", _data);

            _data.Add("</GetFirstTime>");
        }

        public void Top3PricesStock_Changed(IDictionary<string, PriceLibrary.PriceService.StockBase> top3Prices)
        {
            _data.Add("<Top3PricesStockChanged>");

            AddItems(top3Prices.Keys.ToArray(), "Top3Prices", _data);

            _data.Add("</Top3PricesStockChanged>");
        }

        public void MarketInfo_Changed(IDictionary<int, PriceLibrary.PriceService.StockBase> marketinfos)
        {
            var list = new List<string>();
            
            foreach (int i in marketinfos.Keys)
            {
                list.Add(i.ToString());
            }

            AddItems(list.ToArray(), "MarketInfoChanged", _data); 
        }

        public void PutThroughTopPrices_Changed(IList<PriceLibrary.PriceService.StockInfoDyns> newStockbase)
        {
            var list = new List<string>();

            foreach (PriceLibrary.PriceService.StockInfoDyns stock in newStockbase)
            {
                list.Add(stock.StockSymbol);
            }

            AddItems(list.ToArray(), "PutThroughTopPrices", _data);
        }

        public void PutThroughTransactions_Changed(IList<PriceLibrary.PriceService.Transaction> newStockbase)
        {
            var list = new List<string>();

            foreach (PriceLibrary.PriceService.Transaction stock in newStockbase)
            {
                list.Add(stock.Symbol);
            }

            AddItems(list.ToArray(), "PutThroughTransactions", _data);
        }
        
    }
}
